#!/bin/bash

# 验证指定用户名是否在本系统上存在

source kyo_libs


# 方法一:
for_find() {
    debug "For"
    for name in $(cut -d: -f1 /etc/passwd) ; do
        isExists $user $name && myexit "$user 存在"
    done
}

# 方法二:
while_find() {
    debug "While"
    while IFS=":" read name x ; do
        isExists $user $name && myexit "$user 存在"
    done < /etc/passwd
}

# 方法三:
grep_find() {
    debug "Grep"
    egrep -w -q "^$user" /etc/passwd && myexit "$user 存在"
}

#------------------------------------------------------------------------------
KYO_OUT=${KYO_OUT:-yes}

user="$1"

while test -z "$user" ; do
    read -p "请输入用户名: " user
done

${FIND:-grep}_find

myexit "$user 不存在" 1

